﻿using Dto.Core.Database;
using AutoMapper.Extensions.EnumMapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Core.Utility.Helper;
using Core.Database.Model;
using Entity.Core.Database;

namespace Mapper.Core.Database
{
    /// <summary>
    /// 数据库配置 Mapper 配置文件
    /// </summary>
    public class DatabaseConfigMapperProfile:BaseMapperProfile
    {
        /// <summary>
        /// 默认构造
        /// </summary>
        public DatabaseConfigMapperProfile()
        {
            //数据库配置
            CreateMap<DatabaseConfigEntity, DatabaseConfigDto>()
                .ForMember(dest => dest.Error, opt => opt.Ignore())
                .ForMember(dest => dest.DtoMode, opt => opt.MapFrom(p=>p.EntityMode))
                .ForMember(dest => dest.Port, opt => opt.MapFrom(p => ValueTypeConvertHelper.ToInt(p.Port,0)))
                .ReverseMap();

            CreateMap<DatabaseConfig, DatabaseConfigDto>()
                .ForMember(dest => dest.Error, opt => opt.Ignore())
                .ForMember(dest => dest.DtoMode, opt => opt.Ignore())
                .ForMember(dest => dest.Port, opt => opt.MapFrom(p => ValueTypeConvertHelper.ToInt(p.Port, 0)))
                .ReverseMap();

            CreateMap<DatabaseConfigEntity, DatabaseConfigEntity>()
                .ForMember(dest => dest.Port, opt => opt.MapFrom(p => ValueTypeConvertHelper.ToInt(p.Port, 0)))
                .ReverseMap();
        }
    }
}
